<%@page import="java.io.File"%>
<%@page import="org.apache.commons.fileupload.FileItem"%>
<%@page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
<%@page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>
<%@include file="package.jsp" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%@include file="includ.jsp" %>
<%-- <%
request.setCharacterEncoding("utf-8");
long stuno=Long.parseLong(request.getParameter("stuno"));
String sname=request.getParameter("sname");
String sex=request.getParameter("sex");
String telephone=request.getParameter("telephone");
String enter=request.getParameter("enterdate");
if(enter.equals("null")){
	enter="";
}
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");

Date enterdate=(enter.equals("")?null:format.parse(enter)) ;

out.print(stuno);
out.print(sname);
StudentSerive ss=new StudentSerive();
Student stu=new Student();
stu.setSname(sname);
stu.setStuno(stuno);
stu.setSex(sex);
stu.setTelephone(telephone);
int a=ss.update(stu);
if(a>0){
	out.print("保存成功");
	response.sendRedirect("studentshow.jsp");
	return;
}else{
	out.print("保存失败");
%>	 --%>

<%-- <a herf="studentshow.jsp">查看学生信息</a> 
<% }
%> --%>
<%
DiskFileItemFactory factory = new DiskFileItemFactory(); 
//设置缓冲区大小 
factory.setSizeThreshold(1024 * 100); 
//设置临时文件路径 
//factory.setRepository(tempFile); 
//创建文件上传处理器 
ServletFileUpload upload = new ServletFileUpload(factory); 
upload.setHeaderEncoding("utf-8");
Student stu=new Student();
List<FileItem> list=upload.parseRequest(request);
for(FileItem f:list){
%>
<%
if(f.isFormField()){
	out.print("这是表单元素："+f.getFieldName()+",值是："+f.getString("utf-8"));
	if(f.getFieldName().equals("stuno")){
		stu.setStuno(Long.parseLong(f.getString("utf-8")));
		
	}
	if(f.getFieldName().equals("sname")){
		stu.setSname(f.getString("utf-8"));
		
	}	if(f.getFieldName().equals("sex")){
		
		stu.setSex(f.getString("utf-8"));
		
	}
	if(f.getFieldName().equals("telephone")){
		stu.setTelephone(f.getString("utf-8"));
	}
	if(f.getFieldName().equals("qq")){
		stu.setQq(f.getString("utf-8"));
	}
	if(f.getFieldName().equals("wechat")){
		stu.setWechat(f.getString("utf-8"));
	}	
	if(f.getFieldName().equals("gradeid")){
		stu.setGradeid(Long.parseLong(f.getString("utf-8")));
	}
	if(f.getFieldName().equals("enterdate")){
		String enter=f.getString("utf-8");
		if(enter.equals("null")){
			enter="";
		}
		SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");

		Date enterdate=(enter.equals("")?null:format.parse(enter));
		stu.setEnterdate(enterdate);
	}
	if(f.getFieldName().equals("fromcity")){
		stu.setFromcity(f.getString("utf-8"));
	}
	if(f.getFieldName().equals("birthday")){
		String birth=f.getString("utf-8");
		if(birth.equals("null")){
			birth="";
		}
		SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");

		Date birthday=(birth.equals("")?null:format.parse(birth));
		stu.setBirthday(birthday);
	}
	if(f.getFieldName().equals("address")){
		stu.setAddress(f.getString("utf-8"));
	}
	if(f.getFieldName().equals("pass")){
		stu.setPass(f.getString("utf-8"));
	}
	
	
}else{
	out.print("这是文件元素");
	if(f.getSize()==0){
		continue;
	}
	out.print("文件名："+f.getName()+"元素名"+f.getFieldName());
	File path=new File("E:\\新建文件夹\\JAVA应用\\新建文件夹 (2)\\JavaWeb12-4\\WebContent\\imges");
		
	if(path.exists()==false){
		path.mkdir();
	}
	out.print(application.getRealPath("imges")+"---");
	String suffix=f.getName().substring(f.getName().lastIndexOf("."));
	String newname=UUID.randomUUID()+suffix;
	f.write(new File(path,newname));
	
	if(f.getFieldName().equals("pic")){
		stu.setPhoto("imges/"+newname);
	}
	
}%>
<%}
StudentSerive ss=new StudentSerive();
int a=ss.update(stu);
if(a>0){
	out.print("保存成功");
	response.sendRedirect("studentshow.jsp");
	return;
}else{
	out.print("保存失败");
}%>
<%=a %>
 <a herf="studentshow.jsp">查看学生信息</a> 
</body>
</html>